package com.codebase.alicloud.oss;

/**
 * describe:
 * author:houkai
 * Date: 2018/3/5 13:54
 * @version 1.0
 */
public enum FileExtensionEnum {
    /** image/bmp */
    BMP (".bmp", "image/bmp"),
    /** image/gif */
    GIF (".gif", "image/gif"),
    /** image/jpeg */
    JEPG (".jpeg", "image/jpeg"),
    /** BMP */
    JPG (".jpg", "image/jpeg"),
    /** image/jpeg */
    PNG (".png", "image/jpeg"),
    /** text/html */
    HTML (".html", "text/html"),
    /** text/plain */
    TXT (".txt", "text/plain"),
    /** text/plain */
    VSD (".vsd", "text/plain"),
    /** application/vnd.ms-powerpoint */
    PPT (".ppt", "application/vnd.ms-powerpoint"),
    /** application/vnd.ms-powerpoint */
    PPTX (".pptx", "application/vnd.ms-powerpoint"),
    /** application/msword */
    DOC (".doc", "application/msword"),
    /** application/msword */
    DOCX (".docx", "application/msword"),
    /** text/xml */
    XML (".xml", "text/xml");

    /**extension 文件拓展名*/
    public final String extension;

    /**POST发送时所需ContentType*/
    public final String contentType;

    FileExtensionEnum(String extension, String contentType) {
        this.extension = extension;
        this.contentType = contentType;
    }

    /**
     * 拓展名转为ContentType
     * @param extension 拓展名
     * @return
     */
    public static String getContentTypeByExtension (String extension) {
        if (extension == null || "".equals(extension.trim())) {
            return FileExtensionEnum.XML.contentType;
        }
        for (FileExtensionEnum type : values()) {
            if (type.extension.equals(extension.trim())) {
                return type.contentType;
            }
        }
        return FileExtensionEnum.XML.contentType;
    }
}
